package com.atmk.atmk.designMode.创建型.原型模式.demo3.深拷贝;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
//手动实现深拷贝
public class Person implements Cloneable {
    private String name;
    private List<String> hobbies;

    // Getters and setters

    @Override
    public Person clone() {
        try {
            Person cloned = (Person) super.clone();
            cloned.hobbies = new ArrayList<>(this.hobbies);  // 手动实现深拷贝（手动复制引用对象）
            return cloned;
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getHobbies() {
        return hobbies;
    }

    public void setHobbies(List<String> hobbies) {
        this.hobbies = hobbies;
    }
}
